<template>
  <el-dialog
    v-model="dialogVisible"
    :title="ruleForm.status == 1 ? '通过' : '拒绝'"
    width="30%"
    :before-close="handleClose"
  >
    <div class="class-dialog">
      <el-form
        inline
        ref="ruleFormRef"
        :model="ruleForm"
        :rules="rules"
        label-width="100px"
      >
        <el-form-item label="审核意见" prop="remark" style="width: 100%">
          <el-input
            placeholder="审核意见"
            style="width: 100%"
            type="textarea"
            :row="2"
            v-model="ruleForm.remark"
          />
        </el-form-item>
      </el-form>
    </div>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">关闭</el-button>
        <el-button type="primary" @click="submit"> 提交 </el-button>
      </span>
    </template>
  </el-dialog>
</template>
<script setup>
import { auditApi } from "@/plugins/api/shopping/withdrawal";

let ruleForm = ref({});
let rules = {
  remark: [{ required: true, message: "审核意见", trigger: "blur" }],
};
let dialogVisible = ref(false);
function handleClose(done) {
  // dialogVisible.value = false;
  ElMessageBox.confirm("是否确定关闭此对话框?")
    .then(() => {
      done();
    })
    .catch(() => {
      // catch error
    });
}

let ruleFormRef = ref(null);
function initFun(type, row) {
  if (ruleFormRef.value) {
    ruleFormRef.value.resetFields();
  }
  ruleForm.value = {};
  ruleForm.value.status = type;
  ruleForm.value.code = row.code;

  dialogVisible.value = true;
}

const emit = defineEmits(["refreshList"]);
function submit() {
  if (!ruleFormRef.value) return;
  ruleFormRef.value.validate((valid, fields) => {
    if (valid) {
      if (ruleForm.value.status == 1) {
        auditApi(ruleForm.value).then((data) => {
          ElMessage.success("已通过！");
          dialogVisible.value = false;
          emit("refreshList");
        });
      } else {
        auditApi(ruleForm.value).then((data) => {
          ElMessage.success("已拒绝！");
          dialogVisible.value = false;
          emit("refreshList");
        });
      }
    }
  });
}

onMounted(() => {});
defineExpose({
  initFun,
});
</script>
<style scoped lang="scss">
.class-dialog {
  :deep(.el-form-item) {
    width: 50%;
    margin-right: 0;
    padding-right: 10px;
    box-sizing: border-box;
    .el-input {
      width: 100%;
    }
  }

  .img-box {
    display: inline-block;
    margin-right: 5px;
    // margin-bottom: 10px;
    width: 148px;
    position: relative;

    img {
      width: 100%;
      height: 140px;
      object-fit: cover;
    }

    .occlusion {
      display: none;
      width: 100%;
      height: 140px;
      background: #9e9c9c75;
      position: absolute;
      top: 0;
      left: 0;
      z-index: 99;
      text-align: center;

      .del {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        line-height: 148px;
        color: #464444;
        cursor: pointer;
        font-size: large;

        &:hover {
          color: rgb(130, 131, 133);
        }
      }
    }

    &:hover {
      .occlusion {
        display: block;
      }
    }
  }
}
</style>
